London | 25-SDC-July | Andrei Filippov | Sprint 2 | jq exercises #106
London | 25-SDC-July | Andrei Filippov | Sprint 2 | jq exercises #106Droid-An wants to merge 4 commits intoCodeYourFuture:mainfrom
Conversation
LonMcGregor
left a comment
There was a problem hiding this comment.
Good work on this sprint. Your solutions work, but there may be ways they could be simplified
jq/script-11.sh
Outdated
| # The input for this script is the scores.json file. | ||
| # TODO: Write a command to output the total of adding together all scores from all games from all players. | ||
| # Your output should be exactly the number 164. | ||
| jq '[.[].scores] | add | add' scores.json No newline at end of file |
There was a problem hiding this comment.
You could probably simplify this command to only need a single add. Can you figure out how to do this?
There was a problem hiding this comment.
Hm, the only solution that comes to my mind is to use flatten method
jq/script-05.sh
Outdated
| # The input for this script is the scores.json file. | ||
| # TODO: Write a command to output the names of each player, as well as their city. | ||
| # Your output should contain 6 lines, each with two words on it. | ||
| jq -r '.[]| {"name":.name, "city":.city} | join(" ")' scores.json No newline at end of file |
There was a problem hiding this comment.
Your solution of constructing a new json object and joining it works, but you could probably simplify it a bit. Do you know how to directly build a string in a jq command?
There was a problem hiding this comment.
Oh, cool. I didn't know that I can concatenate strings in jq, but now I know that I need to use + operator to do it.
|
Yes, string concatenation makes things a bit simpler. Good work using that. As for your solution using Remember what the |
|
Great work solving this - you are done with this sprint task now |
Learners, PR Template
Self checklist
Changelist
done exercises
Questions
no questions